from PyQt5.QtWidgets import QFileSystemModel, QFileIconProvider, QTreeView, QMenu, QAction
from PyQt5.QtCore import QDir, QFileInfo, Qt
from PyQt5.QtGui import QIcon
from config.config import Config
import os


# 给QFileSystemModel设置自定义图标
class CustomIconProvider(QFileIconProvider):
    def __init__(self):
        super().__init__()
        self.custom_icons = {
            'folder': QIcon(os.path.join(Config.svg_path, 'folder.svg')),
            'file': QIcon(os.path.join(Config.svg_path, 'file.svg'))
        }

    def icon(self, type):
        if isinstance(type, QFileIconProvider.IconType):
            if type == QFileIconProvider.Folder:
                return self.custom_icons['folder']
            elif type == QFileIconProvider.File:
                return self.custom_icons['file']
        elif isinstance(type, QFileInfo):
            if type.isDir():
                return self.custom_icons['folder']
            else:
                return self.custom_icons['file']
        return super().icon(type)
